package 程序员面试金典;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class 数对和 {

    public List<List<Integer>> pairSums(int[] nums, int target) {
        Arrays.sort(nums);
        List<List<Integer>> lists = new LinkedList<>();
        int i=0,j=nums.length;
        while (i<j){
            if (nums[i]+nums[j]==target){
                List<Integer> list = new LinkedList<>();
                list.add(nums[i]);
                list.add(nums[j]);
                lists.add(list);
                i++;
                j--;
            }
            else if (nums[i]+nums[j]<target)
                i++;
            else
                j--;
        }
        return lists;
    }
}
